var t = getApp();

Page({
    data: {
        baseUrl: t.globalData.baseUrl,
        urlBase: t.globalData.urlBase,
        currentTab: 0,
        countDownDay: 0,
        countDownHour: "00",
        countDownMinute: "00",
        countDownSecond: "00"
    },
    onLoad: function(t) {
        var a = this;
        a.setData({
            activityId: t.id,
            type: t.type
        }), a.getinitData();
    },
    getinitData: function() {
        var a = this, e = t.globalData.urlBase + t.globalData.urlactivitydetailList;
        wx.request({
            url: e,
            data: {
                activityId: a.data.activityId,
                type: a.data.type,
                lng: t.globalData.lng,
                lat: t.globalData.lat
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                var e = JSON.parse(t.data);
                0 != e.code ? wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 2e3
                }) : (a.setData({
                    store: e.store,
                    serverList: e.serverList,
                    activity: e.activity,
                    imgUrls: e.activity.imgs.split(","),
                    type: a.data.type,
                    lat: e.store.lat,
                    lng: e.store.lng,
                    name: e.store.name,
                    address: e.store.address,
                    shareName: e.activity.name ? e.activity.name : "",
                    shareImg: e.activity.imgs.split(",")[0] ? e.activity.imgs.split(",")[0] : ""
                }), a.test(e.activity.endTime));
            },
            fail: function(t) {
                console.log(".....fail.....");
            }
        });
    },
    test: function(t) {
        var a = this, e = Date.parse(new Date(t.replace(/-/g, "/"))) / 1e3, n = setInterval(function() {
            var t = Date.parse(new Date()) / 1e3, o = e - t, i = o, r = Math.floor(i / 3600 / 24), s = r.toString();
            1 == s.length && (s = "0" + s);
            var l = Math.floor((i - 3600 * r * 24) / 3600), c = l.toString();
            1 == c.length && (c = "0" + c);
            var u = Math.floor((i - 3600 * r * 24 - 3600 * l) / 60), d = u.toString();
            1 == d.length && (d = "0" + d);
            var g = (i - 3600 * r * 24 - 3600 * l - 60 * u).toString();
            1 == g.length && (g = "0" + g), a.setData({
                countDownDay: s,
                countDownHour: c,
                countDownMinute: d,
                countDownSecond: g
            }), --o < 0 && (clearInterval(n), wx.showToast({
                title: "活动已结束"
            }), a.setData({
                countDownDay: "00",
                countDownHour: "00",
                countDownMinute: "00",
                countDownSecond: "00"
            }));
        }, 1e3);
    },
    openMap: function() {
        var t = this;
        wx.openLocation({
            latitude: parseFloat(t.data.lat),
            longitude: parseFloat(t.data.lng),
            name: t.data.name,
            address: t.data.address
        });
    },
    swichNav: function(t) {
        var a = this;
        if (this.data.currentTab === t.target.dataset.current) return !1;
        a.setData({
            currentTab: t.target.dataset.current
        });
    },
    groupaction: function(t) {
        wx.navigateTo({
            url: "../activity/detail?id=" + t.currentTarget.dataset.id + "&type=" + t.currentTarget.dataset.type
        });
    },
    serverDetail: function(t) {
        wx.navigateTo({
            url: "../index/detail?id=" + t.currentTarget.dataset.id
        });
    },
    onShareAppMessage: function(t) {
        var a = this;
        return "button" === t.from ? (console.log("来自页面内转发按钮"), console.log(t.target)) : console.log("来自右上角转发菜单"), 
        {
            title: a.data.shareName,
            imageUrl: a.data.baseUrl + "download?id=" + a.data.shareImg,
            success: function(t) {
                console.log("转发成功", t);
            },
            fail: function(t) {
                console.log("转发失败", t);
            }
        };
    }
});